package me.xue.communityhealth.repo;

import com.github.pagehelper.Page;
import me.xue.communityhealth.model.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Repository
@Mapper
public interface UserRepository {

    @Insert("INSERT INTO `user`(`name`,`password`,`idCard`,`phone`,`address`,`gender`,`age`,`portrait`) " +
            "VALUES(#{name},#{password},#{idCard},#{phone},#{address},#{gender},#{age},#{portrait})")
    int save(User user);

    @Update("UPDATE `user` " +
            "SET `name`=#{name},`idCard`=#{idCard},`phone`=#{phone},`address`=#{address},`gender`=#{gender},`age`=#{age},`portrait`=#{portrait} " +
            "WHERE `id`=#{id}")
    int update(User user);

    @Delete("DELETE FROM `user` WHERE `id`=#{id}")
    int delete(int id);

    @Select("SELECT * FROM `user` WHERE `id`=#{id}")
    User findOne(int id);

    @Select("SELECT * FROM `user`")
    Page<User> pagedUsers();
}
